package com.ruoyi.system.outto.goods.impl;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProvider;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.utils.HttpUtil;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.feign.InterfaceFeignService;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.model.domain.ArtRec;
import com.ruoyi.system.model.domain.GameAttribute;
import com.ruoyi.system.model.domain.GoodsInfoImg;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.model.service.UploadService;
import com.ruoyi.system.outto.GameContentUtils;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.dto.TencentCOSUtil;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.goods.AdapterApi;
import com.ruoyi.system.token.vo.ApiResponse;
import com.ruoyi.system.utils.AliUtils;
import com.ruoyi.system.utils.MultipartFileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.HttpCookie;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/5 16:19
 */
@Slf4j
@Service
public class AdapterApiImpl implements AdapterApi {

    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Value("${desc.title}")
    private String descTitle;
    @Autowired
    private CommonApi commonApi;
    @Autowired
    private RedisCache redisCache;
    @Autowired
    private SysDictDataMapper sysDictDataMapper;
    static Path imgUrl;
    String APPID = "ceshidandufuwu";
    String APPSECRET = "402883e48a69a2e7018a69a2e7500000";
    String APPFLAGTITLE = "true";
    String APPFLAGDES = "true";
    @Resource
    private UploadService uploadService;

    @Autowired
    private InterfaceFeignService interfaceFeignService;


    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto dto, SalePartner salePartner) {
        //价格控制  多少以下不推送
//        controlPrices(dto,salePartner);

        initialization();
        Map<String, Object> result = new HashMap<>();
        String token = getToken();
        //供应商
        if (Objects.isNull(salePartner) || !salePartner.getStatus().equals("1")) {
            throw new GlobalException("供应商未找到或者已禁用");
        }
        dto.setSalePartner(salePartner);

        // 重构商品属性
        builderGameParam(dto, salePartner,"add");
        log.info("请求参数: " + JSONObject.toJSONString(dto));

        Long time = System.currentTimeMillis();
        AjaxResult publish = null;
        try {
            publish = interfaceFeignService.publish(token, String.valueOf(time), "sign", dto);
            JSONObject res = JSONObject.parseObject(JSONObject.toJSONString(publish));
            System.out.println(salePartner.getSaleName() + " addGame接口返回参数:" + res);
            if ("200".equals(res.getString("code"))) {
                res = res.getJSONObject("data");
                String outId = res.getString("outId");
                if (StringUtils.isNotEmpty(outId)) {
                    ArtRec artRecreq = new ArtRec();
                    artRecreq.setConfig(salePartner.getId());
                    artRecreq.setAccountId(dto.getId());
                    List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
                    if (CollectionUtils.isNotEmpty(artRecs)) {
                        artRecs.get(0).setOutid(outId);
                        artRecMapper.updateArtRec(artRecs.get(0));
                    } else {
                        artRecreq.setAccountId(dto.getId());
                        artRecreq.setCreateId(dto.getCreateId());
                        artRecreq.setType(LCConstant.interAdd);
                        artRecreq.setConfig(salePartner.getId());
                        artRecreq.setSaleCode(salePartner.getSaleName());
                        artRecreq.setOutid(outId);
                        artRecMapper.insertArtRec(artRecreq);
                    }
                    result.put("code", 200);
                } else {
                    result.put("req", res.get("req"));
                    result.put("res", res.get("res"));
                    result.put("msg", res.get("msg"));
                    result.put("code", 500);
                }
                result.put("req", res.get("req"));
                result.put("res", res.get("res"));
                result.put("msg", res.get("msg"));
                return AjaxResult.success(result);
            } else {
                result.put("code", 500);
                result.put("req", JSONObject.toJSONString(dto));
                result.put("res", res);
                result.put("msg", res.getString("msg"));
            }
        } catch (Exception e) {
            result.put("code", 500);
            result.put("req", JSONObject.toJSONString(dto));
            result.put("res", e.getMessage());
            result.put("msg", e.getMessage());
            return AjaxResult.success(result);
        }
        return AjaxResult.success(result);
    }


    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto dto, SalePartner salePartner) {
        initialization();

        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(dto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        if (CollectionUtils.isNotEmpty(artRecs)) {
            dto.setOutId(artRecs.get(0).getOutid());
        } else {
            throw new GlobalException("没有三方ID!!!");
        }

        Map<String, Object> result = new HashMap<>();
        String token = getToken();
        //供应商
        if (Objects.isNull(salePartner) || !salePartner.getStatus().equals("1")) {
            throw new GlobalException("供应商未找到或者已禁用");
        }
        dto.setSalePartner(salePartner);

        // 重构商品属性
        builderGameParam(dto, salePartner,"edit");
        log.info("请求参数: " + JSONObject.toJSONString(dto));



        log.info("editGame请求参数: " + JSONObject.toJSONString(dto));

        Long time = System.currentTimeMillis();
        AjaxResult publish = null;
        try {
            publish = interfaceFeignService.edit(token, String.valueOf(time), "sign", dto);
        } catch (Exception e) {
            throw new GlobalException("接口服务连接异常,没拿到返回参数！");
        }
        JSONObject res = JSONObject.parseObject(JSONObject.toJSONString(publish));
        log.info(salePartner.getSaleName() + " editGame接口返回参数:" + res);
        if ("200".equals(res.getString("code"))) {
            res = res.getJSONObject("data");
            if (res.getString("code").equals("200")) {
                result.put("code", 200);
                if(dto.getGameName().equals("王者荣耀")
                        ||salePartner.getSaleName().contains("MJY")
                        ||salePartner.getSaleName().equals("QIANTSQ")
                        ||salePartner.getSaleName().equals("NIGUANG")
                ){
                    String outId = res.getString("outId");
                    if (StringUtils.isNotEmpty(outId)) {
                        artRecreq = new ArtRec();
                        artRecreq.setConfig(salePartner.getId());
                        artRecreq.setAccountId(dto.getId());
                        artRecs = artRecMapper.selectArtRecList(artRecreq);
                        if (CollectionUtils.isNotEmpty(artRecs)) {
                            artRecs.get(0).setOutid(outId);
                            artRecMapper.updateArtRec(artRecs.get(0));
                        } else {
                            artRecreq.setAccountId(dto.getId());
                            artRecreq.setCreateId(dto.getCreateId());
                            artRecreq.setType(LCConstant.interAdd);
                            artRecreq.setConfig(salePartner.getId());
                            artRecreq.setSaleCode(salePartner.getSaleName());
                            artRecreq.setOutid(outId);
                            artRecMapper.insertArtRec(artRecreq);
                        }
                    }
                }
            } else {
                result.put("code", 500);
            }
            result.put("req", res.get("req"));
            result.put("res", res.get("res"));
            result.put("msg", res.get("msg"));
            return AjaxResult.success(result);
        } else {
            result.put("code", 500);
            result.put("req", JSONObject.toJSONString(dto));
            result.put("res", res);
            result.put("msg", res.getString("msg"));
        }

        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto dto, SalePartner sa) {
        initialization();
        Map<String, Object> result = new HashMap<>();
        String token = getToken();
        //供应商
        if (Objects.isNull(sa) || !sa.getStatus().equals("1")) {
            throw new GlobalException("供应商未找到或者已禁用");
        }
        dto.setSalePartner(sa);

        // 重构商品属性
        builderGameParam(dto, sa,"del");

        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(sa.getId());
        artRecreq.setAccountId(dto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        if (CollectionUtils.isNotEmpty(artRecs)) {
            dto.setOutId(artRecs.get(0).getOutid());
        } else {
            throw new GlobalException("没有三方ID!!!");
        }
        System.out.println("delGame请求参数: " + JSONObject.toJSONString(dto));

        Long time = System.currentTimeMillis();
        AjaxResult publish = null;
        try {
            publish = interfaceFeignService.off(token, String.valueOf(time), "sign", dto);
            System.out.println(JSONObject.toJSONString(publish));
        } catch (Exception e) {
            result.put("code", 500);
            result.put("req", JSONObject.toJSONString(dto));
            result.put("res", publish);
            result.put("msg", e.getMessage());
            return AjaxResult.success(result);
        }
        JSONObject res = JSONObject.parseObject(JSONObject.toJSONString(publish));
        System.out.println(sa.getSaleName() + " delGame接口返回参数:" + res);
        if ("200".equals(res.getString("code"))) {
            JSONObject jsonObject = res.getJSONObject("data");
            if (jsonObject.getString("code").equals("200")) {
                res = res.getJSONObject("data");
                if (StringUtils.isEmpty(res.getString("isdel"))) {
                    if (CollectionUtils.isNotEmpty(artRecs)) {
                        artRecMapper.deleteArtRecById(artRecs.get(0).getId());
                    }
                }
                result.put("code", 200);
            } else {
                res = res.getJSONObject("data");
                result.put("code", 500);
            }
            result.put("req", res.get("req"));
            result.put("res", res.get("res"));
            result.put("msg", res.get("msg"));
            return AjaxResult.success(result);
        } else {
            result.put("code", 500);
            result.put("req", JSONObject.toJSONString(dto));
            result.put("res", res.getString("res"));
            result.put("msg", res.getString("msg"));
        }

        return AjaxResult.success(result);
    }

    public void controlPrices(GoodsInfoAndAttrValueDto dto, SalePartner salePartner) {
//        if(salePartner.getSaleName().equals("PANGXIE")){
//            if(dto.getPrice().intValue()>1000){
//                throw new GlobalException("螃蟹一千以上不推送!!!");
//            }
//        }
    }

    private GoodsInfoAndAttrValueDto builderGameParam(GoodsInfoAndAttrValueDto dto, SalePartner salePartner,String type) {
        //  区服构建
        serviceGroup(dto);
        //  F属性构建
        fBuildParam(dto);
        // 图片
        imgBuild(dto, salePartner,type);
        // 定制属性
        builderParam(dto, salePartner.getSaleName());
        return dto;
    }


    // 区服构建
    private void serviceGroup(GoodsInfoAndAttrValueDto dto) {
        // 区服构建
        String infoV2 = ""; // 区服

        if(dto.getGameName().equals("永劫无间")){
            infoV2 = getGameInfoV2(12l);//属性
        }else if(dto.getGameName().equals("无畏契约")){
            infoV2 = getGameInfoV2(29l);//属性
        }else if(dto.getGameName().equals("永劫无间手游")){
            infoV2 = getGameInfoV2(31l);//属性
        }else {
            infoV2 = getGameInfoV2(dto.getGameId());//属性
        }
        JSONObject servetJson = JSONObject.parseObject(infoV2);
        if (StringUtils.isNotEmpty(servetJson.getString("systems"))) {
            List<JSONObject> systems = JSONObject.parseArray(servetJson.getString("systems"), JSONObject.class);
            Map<String, JSONObject> collect = systems.stream().collect(Collectors.toMap(s -> s.getString("fieldName"), s -> s));
            if (StringUtils.isEmpty(dto.getSystemName()) || Objects.isNull(collect.get(dto.getSystemName().trim()))) {
                throw new GlobalException("未匹配到精准systems :" + dto.getSystemName() + "终端数据" + collect);
            } else {
                JSONObject object = collect.get(dto.getSystemName().trim());
                dto.setSystemId(Long.valueOf(object.getString("id")));
                dto.setSystemName(object.getString("fieldName"));
            }
        }
        if (StringUtils.isNotEmpty(servetJson.getString("carriers"))) {
            List<JSONObject> systems = JSONObject.parseArray(servetJson.getString("carriers"), JSONObject.class);
            Map<String, JSONObject> collect = systems.stream().collect(Collectors.toMap(s -> s.getString("fieldName"), s -> s));
            if (StringUtils.isEmpty(dto.getCarrierName()) || Objects.isNull(collect.get(dto.getCarrierName().trim()))) {
                throw new GlobalException("未匹配到精准carriers :" + dto.getCarrierName() + "终端数据" + collect);
            } else {
                JSONObject object = collect.get(dto.getCarrierName().trim());
                dto.setCarrierId(Long.valueOf(object.getString("id")));
                dto.setCarrierName(object.getString("fieldName"));
            }
        }
        if (StringUtils.isNotEmpty(servetJson.getString("groups"))) {
            List<JSONObject> groups = JSONObject.parseArray(servetJson.getString("groups"), JSONObject.class);
            try {
                Map<String, JSONObject> collect = groups.stream().collect(Collectors.toMap(s -> s.getString("fieldName"), s -> s));
                if (StringUtils.isEmpty(dto.getGroupName()) || Objects.isNull(collect.get(dto.getGroupName().trim()))) {
                    if (StringUtils.isEmpty(dto.getGroupName())) {
                        dto.setGroupName("空字符串");
                    }
                    throw new GlobalException("未匹配到精准groups :" + dto.getGroupName() + "终端数据" + collect);
                } else {
                    JSONObject object = collect.get(dto.getGroupName().trim());
                    dto.setGroupId(Long.valueOf(object.getString("id")));
                    dto.setGroupName(object.getString("fieldName"));
                }
            } catch (Exception e) {
                for(JSONObject jsonObject:groups){
                    if(jsonObject.getString("fieldName").contains(dto.getCarrierName())){
                        dto.setGroupId(Long.valueOf(jsonObject.getString("id")));
                        dto.setGroupName(jsonObject.getString("fieldName"));
                    }
                }
            }
        }
        if (StringUtils.isNotEmpty(servetJson.getString("servers"))) {
            List<JSONObject> servers = JSONObject.parseArray(servetJson.getString("servers"), JSONObject.class);
            try {
                Map<String, JSONObject> collect = servers.stream().collect(Collectors.toMap(s -> s.getString("fieldName"), s -> s));
                if (StringUtils.isEmpty(dto.getServerName()) || Objects.isNull(collect.get(dto.getServerName().trim()))) {
                    if (StringUtils.isEmpty(dto.getServerName())) {
                        dto.setServerName("空字符串");
                    }
                    throw new GlobalException("未匹配到精准servers :" + dto.getServerName() + "终端数据" + collect);
                } else {
                    JSONObject object = collect.get(dto.getServerName().trim());
                    dto.setServerId(Long.valueOf(object.getString("id")));
                    dto.setServerName(object.getString("fieldName"));
                }
            } catch (Exception e) {
                for(JSONObject jsonObject:servers){
                    if(jsonObject.getString("fieldName").contains(dto.getCarrierName())){
                        dto.setServerId(Long.valueOf(jsonObject.getString("id")));
                        dto.setServerName(jsonObject.getString("fieldName"));
                    }
                }
            }
        }
    }

    //f字段属性校验
    private void fBuildParam(GoodsInfoAndAttrValueDto dto) {
        String gameAttrTempV2 = "";
        if(dto.getGameName().equals("永劫无间")){
            gameAttrTempV2 = getGameAttrTempV2(12l);//属性
        }else if(dto.getGameName().equals("英雄联盟")){
            gameAttrTempV2 = getGameAttrTempV2(5l);//属性
        }else if(dto.getGameName().equals("无畏契约")){
            gameAttrTempV2 = getGameAttrTempV2(29l);//属性
        }else if(dto.getGameName().equals("永劫无间手游")){
            gameAttrTempV2 = getGameAttrTempV2(31l);//属性
        }else {
            gameAttrTempV2 = getGameAttrTempV2(dto.getGameId());//属性
        }
        log.info("gameInfo :" + gameAttrTempV2);
        if (StringUtils.isEmpty(gameAttrTempV2)) {
            throw new GlobalException("游戏详情获取失败 ：" + dto.getGameName());
        }
        List<JSONObject> infoArray = JSONObject.parseArray(gameAttrTempV2, JSONObject.class);
        if (CollectionUtils.isEmpty(infoArray)) {
            throw new GlobalException("游戏详情获取失败 ：" + dto.getGameName());
        }
        Map<String, JSONObject> attrTempMap = infoArray.stream().collect(Collectors.toMap(s -> s.getString("aavName"), s -> s));
        if (dto.getGameName().equals("王者荣耀")) {
            wzry(dto, attrTempMap);
        } else if (dto.getGameName().equals("枪战王者")) {
            qzwz(dto, attrTempMap);
        } else if (dto.getGameName().equals("火影忍者")) {
            hyrz(dto, attrTempMap);
        } else if (dto.getGameName().equals("三国杀")) {
            sgs(dto, attrTempMap);
        } else if (dto.getGameName().equals("英雄联盟")) {
//            lol(dto, gameAttrTempV2);
            defaultInfo(dto, attrTempMap);
        } else if (dto.getGameName().equals("原神")) {
            ys(dto, attrTempMap);
        } else if (dto.getGameName().equals("永劫无间")) {
            yjwj(dto, attrTempMap);
        } else {
            defaultInfo(dto, attrTempMap);
        }
//        else if (dto.getGameName().equals("和平精英")) {
//            hpjy(dto, attrTempMap);
//        } else if (dto.getGameName().equals("穿越火线")) {
//            cyhx(dto, attrTempMap);
//        }else if (dto.getGameName().equals("英雄联盟")) {
//            yxlm(dto, attrTempMap);
//        } else if (dto.getGameName().equals("原神")) {
//            ys(dto, attrTempMap);
//        } else if (dto.getGameName().equals("火影忍者")) {
//            hyrz(dto, attrTempMap);
//        } else if (dto.getGameName().equals("永劫无间")) {
//            yjwj(dto, attrTempMap);
//        } else if (dto.getGameName().equals("三国杀")) {
//            sgs(dto, attrTempMap);
//        } else if (dto.getGameName().equals("地下城与勇士")) {
//            dnf(dto, attrTempMap);
//        } else if (dto.getGameName().equals("崩坏星穹铁道")) {
//            benghuai(dto, attrTempMap);
//        }
    }
    static String getToken(SalePartner salePartner) {
        String url1 = "http://api-merchant.pxb7.com/business/login";
        Map<String, String> params1 = new HashMap<>();
        params1.put("user_name", salePartner.getSaleKey());
        params1.put("password", salePartner.getOther());
        String response = com.ruoyi.system.outto.dto.yx7881.utils.HttpUtil.doPost(url1, params1);
        JSONObject jsonObject = JSONObject.parseObject(response);
        if ("200".equals(jsonObject.getString("code"))) {
            String data = jsonObject.getString("data");
            JSONObject jsonObject1 = jsonObject.parseObject(data);
            log.info("token={}", jsonObject1.getString("token"));
            return jsonObject1.getString("token");
        }
        return null;
    }
    static String getOssConfig(SalePartner salePartner) {
        String token = getToken(salePartner);
        String url = "http://api-merchant.pxb7.com/business/getOssConfig";
        String response = HttpRequest.get(url).header("Authorization", token).execute().body();
        return response;
    }

    // 图片构建
    private void imgBuild(GoodsInfoAndAttrValueDto dto, SalePartner salePartner,String type) {
        if(salePartner.getSaleName().contains("MJY")){
            HttpResponse response = getJYMToken();
            //获取到token
            HttpCookie m_h5_tk = response.getCookie("_m_h5_tk");
            String _m_h5_tk = m_h5_tk.getValue();
            log.info("获取到的_m_h5_tk={}", _m_h5_tk);

            HttpCookie m_h5_tk_enc = response.getCookie("_m_h5_tk_enc");
            String _m_h5_tk_enc = m_h5_tk_enc.getValue();
            log.info("_m_h5_tk_enc={}", _m_h5_tk_enc);

            String cookie = "cna=ELz2HdeMWE0CASrvtv8g0GPP; ssids=2151706171272252; logTraceJymId=7979a277a8f7-4ac1-9673-c5c5; track_id=gcmall_1706171272984_20badffa-bff2-468c-ab69-2b489280641e; t=760ce99ede3c17ff4a9854e748e95e99; _bl_uid=bwlgXrU5va1gdbxgmtp0q9ys9p3p; aplus_ieu_ch=10438; ctoken=QLk4nT7MY9W1Ms_5x8BEH0po; _m_h5_tk=" + _m_h5_tk + "; _m_h5_tk_enc=" + _m_h5_tk_enc + "; xlly_s=1; Hm_lvt_47366dcc92e834539e7e9c3dcc2441de=1707798155,1709021805; _samesite_flag_=true; cookie2=1ac5b7e20db0c4ed82b1b12864f05c97; _tb_token_=e6b53b3379018; ieu_member_biz_id=jiaoyimao; csg=ce33c43a; ieu_member_uid=1544521729220323; jym_session_id=" + salePartner.getSaleKey() + "; ieu_member_sid=" + salePartner.getSaleKey() + "; actk=1861a9538d288c8d8ab3a3466972eeee; sfroms=JIAOYIMALL001; external_login_type=2; ssts=960d7b2550750c2473c6488c47426b8c; actks=dc50e594cc88972d7e4b0db1f1fca1b7; EGG_SESS=3v6DgAB-jKbLOzN5Qa1pFi5yHoQKYp1Php5wCXl9Vy7Ix_eco_QOS_jC-0TzxDVnsrktE84L7AheQVsGJ4JQDb6KKG_EzHd85uOlGxc2-IHSUPiqfgb0GIfF9hjMQCbp; session=1709023162661780-9; t_id=0dba2a925449-4eae-96c5-db943e8d4475; p_id=351ffa81d09b-4556-8063-bef2b0a68739; Hm_lpvt_47366dcc92e834539e7e9c3dcc2441de=1709023449; tfstk=ewuMjDAeYcr6NwRmFAU6JOYzhAxpUPa_uIDYH-h4352QQlhqDE4mLfcTXhatx-DEKRrv1NhduxDE6N3xoD_mNjg91rd_5fabuLpJy-cs1r_aP9_pykTLlJpJeULLVcT0NLnOOHjRYkSFJzpxzwE_E_brTJuJSLes_JbosJVaMGwYKZ7qHDcLUUehuZu3sgSlYgWS6ZwJ-jsfclPQt8nOGOEyttDyZBAhqXraOWoDtBjfclPQt8dHtgcUbWNEm; isg=BP7-vrQ6F3QlpUI3-qcVXCpCTxRAP8K5s6p_XqgHQcOsS8QlcM4xy1NtxxGH87rR";
            List<String> string = new ArrayList<>();
            List<Map<String, Object>> images = new ArrayList<>();
            GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
            goodsInfoImg.setGoodsId(dto.getId());
            goodsInfoImg.setType(Constants.STR_1);
            List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
            if(infoImgs.size()>29){
                infoImgs = infoImgs.subList(0,29);
            }
            for(GoodsInfoImg goodsInfoImg1 : infoImgs){
                imgUpload(cookie,_m_h5_tk,goodsInfoImg1.getImgUrl(),string,images);
            }
            if(StringUtils.isNotEmpty(string)){
                dto.setImgUrls(string.stream().collect(Collectors.joining(",")));
                dto.setUrlArr(images);
            }
        }else if(salePartner.getSaleName().equals("QIANTSQ")){
            if(type.equals("add")) {
                String string = upImg(dto.getTitleImg(), salePartner);
                dto.setTitleImg(string);
                GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
                goodsInfoImg.setGoodsId(dto.getId());
                goodsInfoImg.setType(Constants.STR_1);
                List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
                if (infoImgs.size() > 20) {
                    infoImgs = infoImgs.subList(0, 19);
                }
                String imgs = "";
                for (GoodsInfoImg goodsInfoImg1 : infoImgs) {
                    String string1 = upImg(goodsInfoImg1.getImgUrl(), salePartner);
                    if (StringUtils.isNotEmpty(string1)) {
                        imgs += "," + upImg(goodsInfoImg1.getImgUrl(), salePartner);
                    }
                }
                if (StringUtils.isNotEmpty(imgs)) {
                    dto.setImgUrls(imgs.substring(1));
                }
            }
        }else if(salePartner.getSaleName().equals("HOUPANGXIE")) {
            byte[] bytes = AliUtils.downloadPicture(dto.getTitleImg());
            String name = "imageFile" + dto.getTitleImg().substring(dto.getTitleImg().lastIndexOf("."));
            MultipartFile multipartFile = MultipartFileUtil.getMultipartFile(name, bytes);

            String ossConfig = getOssConfig(salePartner);
            String data = JSONObject.parseObject(ossConfig).getString("data");
            String bucket = JSONObject.parseObject(data).getString("bucket");
            String viewDomain = JSONObject.parseObject(data).getString("viewDomain");
            String endpoint = "oss-cn-hangzhou.aliyuncs.com";
            String credentials = JSONObject.parseObject(data).getString("Credentials");
            String accessKeyId = JSONObject.parseObject(credentials).getString("AccessKeyId");
            String accessKeySecret = JSONObject.parseObject(credentials).getString("AccessKeySecret");
            String securityToken = JSONObject.parseObject(credentials).getString("SecurityToken");

            String string = null;
            try {
                string = AliUtils.uploadFile(multipartFile,endpoint,accessKeyId,accessKeySecret,bucket,securityToken,viewDomain);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(StringUtils.isEmpty(string)){
                throw new GlobalException("图片上传失败!!!");
            }
            dto.setTitleImg(string);
            GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
            goodsInfoImg.setGoodsId(dto.getId());
            goodsInfoImg.setType(Constants.STR_1);
            List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
            if(infoImgs.size()>20){
                infoImgs = infoImgs.subList(0,19);
            }
            String imgUrls = "";
            for(GoodsInfoImg goodsInfoImg1 : infoImgs){
                try {
                    bytes = AliUtils.downloadPicture(goodsInfoImg1.getImgUrl());
                    name = "imageFile" + goodsInfoImg1.getImgUrl().substring(goodsInfoImg1.getImgUrl().lastIndexOf("."));
                    multipartFile = MultipartFileUtil.getMultipartFile(name, bytes);
                    string = AliUtils.uploadFile(multipartFile,endpoint,accessKeyId,accessKeySecret,bucket,securityToken,viewDomain);
                    imgUrls+=","+string;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if(StringUtils.isNotEmpty(imgUrls)){
                dto.setImgUrls(imgUrls.substring(1));
            }else{
                throw new GlobalException("图片上传失败!!!");
            }
        }
        else {
            try {
                GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
                goodsInfoImg.setGoodsId(dto.getId());
                goodsInfoImg.setType(Constants.STR_1);
                List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);

                if(salePartner.getSaleName().contains("HONGKAI")){
                    if(infoImgs.size()>31) {
                        infoImgs = infoImgs.subList(0, 30);
                    }
                }

                String imgUrls = "";
                if (StringUtils.isNotEmpty(dto.getTitleImg())) {
                    imgUrls += "," + dto.getTitleImg();
                }
                if (CollectionUtils.isNotEmpty(infoImgs)) {
                    if (StringUtils.isEmpty(dto.getTitleImg())) {
                        dto.setTitleImg(infoImgs.get(0).getImgUrl());
                    }

                    for (GoodsInfoImg goodsInfoImg1 : infoImgs) {
                        imgUrls += "," + goodsInfoImg1.getImgUrl();
                    }
                    if (StringUtils.isNotEmpty(imgUrls)) {
                        dto.setImgUrls(imgUrls.substring(1));
                    }
                } else {
                    dto.setImgUrls(LCConstant.defaultImg);
                }
            } catch (Exception e) {
                throw new GlobalException("图片构建失败! goodsId :" + dto.getId());
            }
        }
    }

    static void imgUpload(String cookie, String _m_h5_tk,String img,List<String> string,List<Map<String, Object>> images) {
        String jsv = "2.7.2";
        String appKey = "12574478";

        String token = _m_h5_tk.split("_")[0];
        String t = String.valueOf(new Date().getTime());

        StringBuffer query = new StringBuffer();
        JSONObject data = new JSONObject();
        data.put("bizId", "1");
        String fieldName = img.substring(img.lastIndexOf("/")+1);
        data.put("fileName", fieldName);

//        String data = "{\"bizId\":\"1\",\"fileName\":\"2c97e7c98e5f3329018e65763ab50c6b.jpg\"}";

        //获取交易猫图片上传 密钥
        String baseUrl = "https://mtop.jiaoyimao.com/h5/mtop.jym.fileserver.applyfileupload/1.0/";
        query.append(token).append("&").append(t).append("&").append(appKey).append("&").append(data);
        String algSign = DigestUtils.md5Hex(query.toString());
        Map<String, Object> params = new HashMap<>();
        Map<String, Object> header = new HashMap<>();
        header.put("Cookie", cookie);
        params.put("data", data.toJSONString());
        params.put("appKey", appKey);
        params.put("t", t);
        params.put("sign", algSign);
        String s = HttpUtils.doPostForm(baseUrl, params, header);
        JSONObject jsonObject = JSONObject.parseObject(s);
        JSONObject data1 = jsonObject.getJSONObject("data");
        JSONObject result = data1.getJSONObject("result");
        JSONObject credentials = result.getJSONObject("credentials");
        String securityToken = credentials.getString("securityToken");
        String accessKeyId = credentials.getString("accessKeyId");
        String accessKeySecret = credentials.getString("accessKeySecret");

        String env = result.getString("pathList");
        List<String> stringList = JSONArray.parseArray(env, String.class);
        String path = stringList.get(0);

        URL url = null;
        byte[] bytes = {};
        try {
            url = new URL(img);
            BufferedImage bufferedImage = ImageIO.read(url.openStream());
            bytes = ImgUntil.bufferedImageToByteArray(bufferedImage);
            //如果是多图片，这里要循环上传图片，最好不要超过五张
            uoload(accessKeyId, accessKeySecret, securityToken, bytes, path);
            //验证图片
            //获取resultId，如果是多张图片 循环往 goodsImageDTOListStr 添加
            List<JSONObject> goodsImageDTOListStr = new ArrayList<>();
            JSONObject goodsImgeDto = new JSONObject();
            goodsImgeDto.put("originImage", "/" + path);
            goodsImgeDto.put("wapThumbnail", "/" + path);
            goodsImgeDto.put("pcThumbnail", "/" + path);
            goodsImgeDto.put("auditImage", "/" + path);
            goodsImageDTOListStr.add(goodsImgeDto);
            JSONObject goodsImageDTOParams = new JSONObject();
            goodsImageDTOParams.put("goodsImageDTOListStr", goodsImageDTOListStr.toString());
            String imgeResultId = getImgeResultId(goodsImageDTOParams.toString(), cookie, _m_h5_tk);


            //add图片上传参数
            //解析imgeResultId
            JSONObject jsonObject1 = JSONObject.parseObject(imgeResultId);
            JSONObject resdata = jsonObject1.getJSONObject("data");
            String result1 = resdata.getString("result");
            List<String> stringList1 = JSONObject.parseArray(result1, String.class);
            string.add(StringUtils.join(stringList1, ","));

            //https://static-cdn.jiaoyimao.com/jym-oss/resource/item/1685196620085637/20240327/7773173425da4ceea74709ea4092a667.jpg
            //童谣如果是多张图片 这也也是循环往images添加
            String baseDomain = "https://static-cdn.jiaoyimao.com/";
            JSONObject image = new JSONObject();
            image.put("url", baseDomain + path);
            image.put("onlinePath", "/" + path);
            images.add(image);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    static HttpResponse getJYMToken() {
        String t = String.valueOf(new Date().getTime());
        String token = "e2a7c26a6f259abbfbf16c92baa01906";
        String _m_h5_tk = token + "_" + t;
        //先请求一个cookie为空

        HttpResponse response = getRes(null, t, token, null);
        String body = response.body();
        log.info("第一次请求={}", body);


        return response;
    }
    public static HttpResponse getRes(String cookie, String t, String token, String data) {

        String baseUrl = "https://mtop.jiaoyimao.com/h5/mtop.com.jym.layout.hsf.goodslist.getgoodslist/1.0/";
        String jsv = "2.7.2";
        String s = "12574478";

        StringBuffer query = new StringBuffer();
        query.append(token).append("&").append(t).append("&").append(s).append("&").append(data);
        String algSign = DigestUtils.md5Hex(query.toString());
        HttpResponse response = HttpRequest.get(baseUrl)
                .form("jsv", jsv)
                .form("appKey", s)
                .form("t", t)
                .form("sign", algSign)
                .form("type", "originaljson")
                .form("v", "1.0")
                .form("valueType", "original")
                .form("dataType", "json")
                .form("api", "mtop.com.jym.layout.hsf.goodslist.getGoodsList")
                .form("preventFallback", "true")
                .form("data", data)
                .header("authority", "mtop.jiaoyimao.com")
                .header("accept", "application/json")
                .header("content-type", "application/x-www-form-urlencoded")
                .header("content-type", "application/x-www-form-urlencoded")
                .header("jym-meta-h5", "{\"sid\":\"5541701826074943\",\"ssids\":\"5541701826074943\",\"platform\":\"JYM_IOS_TOUCH\",\"plat\":\"JYM_IOS_TOUCH\",\"osCode\":\"ios\",\"chCode\":\"h5\",\"ch\":\"10438\",\"vername\":\"\"}")
                .header("cookie", cookie)
                .execute();
        return response;
    }

    public static void uoload(String accessKeyId, String accessKeySecret, String securityToken, byte[] content, String objectName) throws Exception {
        // Endpoint以华东1（杭州）为例，其它Region请按实际情况填写。
        String endpoint = "oss-cn-zhangjiakou.aliyuncs.com";
        // 从环境变量中获取访问凭证。运行本代码示例之前，请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
        CredentialsProvider credentialsProvider = new DefaultCredentialProvider(accessKeyId, accessKeySecret, securityToken);
        // 填写Bucket名称，例如examplebucket。
        String bucketName = "jym-static";
        // 填写Object完整路径，完整路径中不能包含Bucket名称，例如exampledir/exampleobject.txt。


        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);

        try {
            // 创建PutObjectRequest对象。
            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, new ByteArrayInputStream(content));

            // 创建PutObject请求。
            PutObjectResult result = ossClient.putObject(putObjectRequest);

            log.info("PutObjectResult={}",result);

        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
    static String getImgeResultId(String data,String cookie,String _m_h5_tk){
        String baseUrl = "https://mtop.jiaoyimao.com/h5/mtop.jym.jymgoods.goods.publish.addimagerecordlistformtop/1.0/";

        String jsv = "2.7.2";
        String s = "12574478";

        String token = _m_h5_tk.split("_")[0];
        String t = String.valueOf(new Date().getTime());

        StringBuffer query = new StringBuffer();
//        String data = "{\"goodsImageDTOListStr\":[\"[{\"originImage\":\"/jym-oss/resource/item/1685196620085637/20240326/044fdd3a13e54afc8b868246e6112d34.jpg\",\"wapThumbnail\":\"/jym-oss/resource/item/1685196620085637/20240326/044fdd3a13e54afc8b868246e6112d34.jpg\",\"pcThumbnail\":\"/jym-oss/resource/item/1685196620085637/20240326/044fdd3a13e54afc8b868246e6112d34.jpg\",\"auditImage\":\"/jym-oss/resource/item/1685196620085637/20240326/044fdd3a13e54afc8b868246e6112d34.jpg\"},{\"originImage\":\"/jym-oss/resource/item/1685196620085637/20240326/830591fc73214b21adba7c88f862746d.jpg\",\"wapThumbnail\":\"/jym-oss/resource/item/1685196620085637/20240326/830591fc73214b21adba7c88f862746d.jpg\",\"pcThumbnail\":\"/jym-oss/resource/item/1685196620085637/20240326/830591fc73214b21adba7c88f862746d.jpg\",\"auditImage\":\"/jym-oss/resource/item/1685196620085637/20240326/830591fc73214b21adba7c88f862746d.jpg\"}]\"]}";
        log.info("data={}",data);
        //撤回的时候传入商品ID   下架账号之后 都要先调一下撤回
        query.append(token).append("&").append(t).append("&").append(s).append("&").append(data);
        String algSign = DigestUtils.md5Hex(query.toString());
        HttpResponse rawResponse = HttpRequest.post(baseUrl)
                .form("data", data)
                .form("jsv", jsv)
                .form("appKey", s)
                .form("t", t)
                .form("sign", algSign)
                .form("dataType", "json")
                .form("valueType", "original")
                .form("api", "top.jym.jymgoods.goods.publish.addImageRecordListForMtop")
                .form("v", "1.0")
                .form("type", "originaljson")
                .form("preventFallback", "true")
                .header("authority", "mtop.jiaoyimao.com")
                .header("accept", "application/json")
                .header("content-type", "application/x-www-form-urlencoded")
                .header("jym-meta-h5", "{\"sid\":\"4461709102075386\",\"ssids\":\"4461709102075386\",\"ch\":\"10438\",\"plat\":\"JYM_IOS_TOUCH\",\"platform\":\"JYM_IOS_TOUCH\",\"terminal\":\"ios\",\"osCode\":\"ios\",\"chCode\":\"h5\"}")
                .header("cookie", cookie)
                .execute();
        String body = rawResponse.body();
        log.info("获取图片返回结果ID={}",body);
        return body;
    }

    private static String upImg(String imgs,SalePartner salePartner){

        System.out.println("开始：" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        String uploadImg = "https://www.taoshouyou.com/com/webupload/upload?path=trades";
        System.out.println("结束：" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        Map<String, Object> params= new HashMap<>();
        File file = null;
        try {
            URL url = new URL(imgs);
            BufferedImage image = ImageIO.read(url.openStream());
            byte[] bytes = ImgUntil.bufferedImageToByteArray(image);
            long srcSize = bytes.length;
            if (srcSize / 1024 > 5000) {
                bytes = ImgUntilYS.compressPicForScale(bytes, 3072l);
            } else {
                bytes = ImgUntilYS.compressPicForScale(bytes, 2048l);
            }
            file = convert(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        params.put("file",file);
        try {
            String s = HttpRequest.post(uploadImg)
                    .form("file", file)
                    .header("Content-Type","multipart/form-data; boundary=<calculated when request is sent>")
                    .header("Content-Length","<calculated when request is sent>")
                    .header("Host","<calculated when request is sent>")
                    .header("cookie",login(salePartner))
                    .execute().body();
            String string = JSONObject.parseObject(s).getString("result");
            return string;
        }catch (Exception e){
            System.out.println(e);
        }
        return null;
    }
    private static String login(SalePartner salePartner) {
        String loginUrl = "https://passport.taoshouyou.com/api/user/login";
        String userName = salePartner.getSaleKey();
        String picVerifyCode = "";
        String password = salePartner.getOther();

        List<HttpCookie> cookies = HttpRequest.post(loginUrl)
                .form("userName", userName)
                .form("picVerifyCode", picVerifyCode)
                .form("password", password)
                .execute().getCookies();
        StringBuilder cookieStr = new StringBuilder();
        for (HttpCookie cookie : cookies) {
            cookieStr.append(cookie.getName()).append("=").append(cookie.getValue()).append("; ");
        }
        // 去掉最后一个分号和空格
        if (cookieStr.length() > 0) {
            cookieStr.setLength(cookieStr.length() - 2);
        }
        return cookieStr.toString();
    }

    public static String upLoadImg(File file, SalePartner salePartner) {
        Map<String, Object> params = new TreeMap<>();
        Map<String, Object> header = new TreeMap<>();

        String nonce = RandomStringUtils.randomAlphanumeric(8);

        long timestamp = System.currentTimeMillis() / 1000;

        params.put("file", file);

        header.put("appid", salePartner.getSaleKey());
        header.put("timestamp", timestamp);
        header.put("nonce", nonce);
        String URL = "https://api.kkzhw.com/openapi/record/upload_image";
        String cover = "appid=" + salePartner.getSaleKey() + "&nonce=" + nonce + "&timestamp=" + timestamp + "&secret_key=" + salePartner.getOther();
        String encode = HttpUtil.urlEncode(cover, "utf-8");
        String sign = DigestUtils.md5Hex(encode).toUpperCase();
        header.put("sign", sign);
        try {
            String response = HttpRequest.post(URL).form("image", file).header("Content-Type", "multipart/form-data")
                    .header("appid", salePartner.getSaleKey())
                    .header("timestamp", String.valueOf(timestamp))
                    .header("nonce", nonce)
                    .header("sign", sign).execute().body();
            return response;
        } catch (Exception e) {
            return null;
        }
    }

    public static String upLoad(String imgUrl, SalePartner salePartner) {
        try {
            URL url = new URL(imgUrl);
            BufferedImage image = ImageIO.read(url.openStream());
            byte[] bytes = ImgUntil.bufferedImageToByteArray(image);
            File file = convert(bytes);
            try {

                long size = file.length() / 1024;
                if (size > 8000) {
                    bytes = ImgUntilYS.compressPicForScale(bytes, 5120l);
                    file = convert(bytes);
                }
                String s = upLoadImg(file, salePartner);
                file.delete();
                if (StringUtils.isNotEmpty(s)) {
                    return s;
                }
            } catch (IOException e) {
                return null;
            }
        } catch (Exception e) {
            return null;
        }
        return null;
    }

    public static File convert(byte[] byteArray) throws IOException {
        File file = File.createTempFile("kankantemp", ".jpg");
        Path path = Paths.get(file.getAbsolutePath());
        imgUrl = path;
        try (FileOutputStream fos = new FileOutputStream(file)) {
            fos.write(byteArray);
        }catch (Exception e){

        }
        return file;
    }

    // 属性矫正
    private void builderParam(GoodsInfoAndAttrValueDto dto, String saleName) {
        String NUMBER_PATTERN = "^[0-9]*$";

        String accountNumber = dto.getAccountNumber();
        String accountPassword = dto.getAccountPassword();
        String importantRemark = dto.getImportantRemark();

        String thirdId = String.valueOf(dto.getId());  //三方id

        if (StringUtils.isEmpty(dto.getAccountNumber())) {//帐号
            accountNumber = String.valueOf(System.currentTimeMillis());
        }
//        // 个别平台QQ要求纯数值  这里只要是QQ类型的 全改成纯数值
//        if (StringUtils.isNotEmpty(dto.getCarrierName()) && dto.getCarrierName().equals("QQ") && !accountNumber.matches(NUMBER_PATTERN)) {
//            accountNumber = createQQAccount();
//        }
        if (StringUtils.isEmpty(dto.getAccountPassword())) {//密码
            accountPassword = "123456";
        }
        if (StringUtils.isEmpty(dto.getImportantRemark())) {//重要备注
            importantRemark = "无";
        }
        if (StringUtils.isEmpty(dto.getDes())) {
            throw new GlobalException("商品详情信息不可为空");
        }
        if (saleName.contains(LCConstant.saleNameHHB)) {

        } else if (saleName.contains(LCConstant.saleNameJYM)) {
            thirdId = String.valueOf(thirdId);
        } else if (saleName.contains(LCConstant.saleNameKJS)) {
            accountNumber = thirdId;
            //氪金兽thirdId 只能是纯数字 这里做一下处理
            thirdId = String.valueOf(dto.getId());
//            if (saleName.equals(LCConstant.saleNameKJS)) {
//                if (1000 > dto.getPrice().intValue()) {
//                    dto.setPrice(dto.getPrice().add(new BigDecimal("50")));
//                }
//            }
        } else if (saleName.contains(LCConstant.saleName7881)) {
            accountNumber = createQQAccount();
            if(dto.getCarrierName().equals("微信")){
                accountNumber = "wx"+accountNumber;
            }
        }

        dto.setAccountNumber(accountNumber);
        dto.setAccountPassword(accountPassword);
        dto.setImportantRemark(importantRemark);
        dto.setThirdId(thirdId);
        dto.setIsshow(APPFLAGDES); //是否展示编号

        // 价格校验
        if (dto.getPrice().doubleValue() < 10) {
            throw new GlobalException("报价过低");
        }
    }

    private String guolv(String des) {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType("xianyu_check");
        sysDictData.setStatus(Constants.STR_0);
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataList(sysDictData);
        for (SysDictData dictData : sysDictDataList) {
            String value = dictData.getDictValue();
            if (des.contains(value)) {
                des = des.replace(value, "");
            }
        }
        return des;
    }

    private String toCoverImg(String imgUrl) {
        //1、判断图片是否存在.jpg 或者 .png  .JPG .PNG
        //2、不存在开始解析上传七牛云
        //3、返回地址

        boolean b = false;
        if (!(imgUrl.contains(".jpg") || imgUrl.contains(".png") || imgUrl.contains(".JPG") || imgUrl.contains(".PNG")) && (StringUtils.isNotEmpty(imgUrl) || b)) {
            URL url = null;
            try {
                url = new URL(imgUrl);
                BufferedImage image = ImageIO.read(url.openStream());
                byte[] bytes = ImgUntil.bufferedImageToByteArray(image);
                String path = uploadService.upload2Qiniu(bytes, "jym/" + UUIDGenerator.generate() + ".jpg");
                return path;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return imgUrl;
    }

    private String getSMSF(GoodsInfoAndAttrValueDto dto) {
        GameAttribute gameAttribute = null;
        String smSF = "";
        try {
            if (Objects.equals("王者荣耀", dto.getGameName())) {  //2
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF16()));
                if (!Objects.isNull(gameAttribute)) {
                    smSF = gameAttribute.getFieldName();
                }
            }
            if (Objects.equals("和平精英", dto.getGameName())) {//3
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF10()));
                if (!Objects.isNull(gameAttribute)) {
                    smSF = gameAttribute.getFieldName();
                }
            }
            if (dto.getGameName().contains("原神")) { //4
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF20()));
                if (!Objects.isNull(gameAttribute)) {
                    smSF = gameAttribute.getFieldName();
                }
            }
            if (dto.getGameName().contains("英雄联盟")) {//
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF1()));
                if (!Objects.isNull(gameAttribute)) {
                    smSF = gameAttribute.getFieldName();
                }
            }
            if (dto.getGameName().contains("穿越火线")) {//
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF3()));
                if (!Objects.isNull(gameAttribute)) {
                    smSF = gameAttribute.getFieldName();
                }
            }
            if (Objects.equals("枪战王者", dto.getGameName())) {
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF10()));
                if (!Objects.isNull(gameAttribute)) {
                    smSF = gameAttribute.getFieldName();
                }
            }
            if (Objects.equals("QQ飞车手游", dto.getGameName())) {
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF10()));
                if (!Objects.isNull(gameAttribute)) {
                    smSF = gameAttribute.getFieldName();
                }
            }
            if (Objects.equals("火影忍者", dto.getGameName())) {
                if (StringUtils.isNotEmpty(dto.getF10())) {
                    gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF10()));
                    if (!Objects.isNull(gameAttribute)) {
                        smSF = gameAttribute.getFieldName();
                    }
                }
            }
        } catch (Exception e) {
            throw new GlobalException("实名信息为空");
        }
        return smSF;
    }

    // 构建属性
    public String builderFParam(JSONObject paramF, String localF, String type) {
        String res = null;
        if (StringUtils.isNotEmpty(localF)) {
            if (StringUtils.equals("0", localF)) {
                log.info(paramF.getString("aavName") + "选项value 为:" + localF);
            }
            if (StringUtils.equals("radio", type)) {
                if (StringUtils.equals("0", localF)) {
                    localF = null;
                } else {
                    String values = paramF.getString("values");
                    List<JSONObject> f1Array = JSONObject.parseArray(values, JSONObject.class);
                    GameAttribute attribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(localF));
                    if (!Objects.isNull(attribute)) {
                        for (JSONObject jsonObject : f1Array) {
                            if (jsonObject.getString("fieldName").contains(attribute.getFieldName())) {
                                res = jsonObject.getString("id");
                                break;
                            }
                        }
                    }
                }
            } else if (StringUtils.equals("boxradio", type)) {
                if (StringUtils.equals("0", localF)) {
                    localF = null;
                } else {
                    String values = paramF.getString("values");
                    List<JSONObject> f1Array = JSONObject.parseArray(values, JSONObject.class);
                    List<JSONObject> list = new ArrayList<>();
                    for (JSONObject jsonObject : f1Array) {
                        String child = jsonObject.getString("child");
                        List<JSONObject> array = JSONObject.parseArray(child, JSONObject.class);
                        for (JSONObject j : array) {
                            list.add(j);
                        }
                    }
                    List<GameAttribute> gameAttributes = gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(localF.split(","), Long.class));
                    StringBuilder sb = new StringBuilder("");
                    StringBuilder bs = new StringBuilder("");
                    if (CollectionUtils.isNotEmpty(gameAttributes)) {
                        for (GameAttribute gameAttribute : gameAttributes) {
                            for (JSONObject jsonObject : list) {
                                if (jsonObject.getString("fieldName").contains(gameAttribute.getFieldName())) {
                                    sb.append("," + jsonObject.getString("id"));
                                    break;
                                }
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(sb)) {
                        res = sb.substring(1);
                    }
                }
            } else if (StringUtils.equals("checkbox", type)) {
                if (StringUtils.equals("0", localF)) {
                    localF = null;
                } else {
                    String values = paramF.getString("values");
                    List<JSONObject> f1Array = JSONObject.parseArray(values, JSONObject.class);
                    List<GameAttribute> gameAttributes = gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(localF.split(","), Long.class));
                    StringBuilder sb = new StringBuilder("");
                    StringBuilder bs = new StringBuilder("");
                    if (CollectionUtils.isNotEmpty(gameAttributes)) {
                        for (GameAttribute gameAttribute : gameAttributes) {
                            for (JSONObject jsonObject : f1Array) {
                                if (jsonObject.getString("fieldName").contains(gameAttribute.getFieldName())) {
                                    sb.append("," + jsonObject.getString("id"));
                                    break;
                                }
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(sb)) {
                        res = sb.substring(1);
                    }
                }
            } else if (StringUtils.equals("input", type)) {

                res = localF;
            } else if (StringUtils.equals("number", type)) {

                res = localF;
            } else {
                throw new GlobalException("不支持此类型 : " + type);
            }
        }
//        if (paramF.getString("must").equals("true")) {
//            if (StringUtils.isEmpty(res)) {
//                throw new GlobalException("缺少必要参数 " + paramF.getString("aavName") + paramF.getString("fieldName") + "   param: " + localF);
//            }
//        }
        return res;
    }

    public void qzwz(GoodsInfoAndAttrValueDto dto, Map<String, JSONObject> attrTempMap) {
        if (!Objects.isNull(attrTempMap.get("f1"))) {
            if (StringUtils.isEmpty(dto.getF1())) {
                dto.setF1("1");
            } else {
                dto.setF1(dto.getF1());
            }
        }
        if (!Objects.isNull(attrTempMap.get("f2"))) {
            JSONObject f2 = attrTempMap.get("f2");
            if (StringUtils.isNotEmpty(dto.getF2())) {
                dto.setF2(builderFParam(f2, dto.getF2(), f2.getString("fieldType")));
            } else {
                dto.setF2("41722");
            }
        }
        if (!Objects.isNull(attrTempMap.get("f3"))) {
            JSONObject f3 = attrTempMap.get("f3");
            dto.setF3(builderFParam(f3, dto.getF3(), f3.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f4"))) {
            JSONObject f4 = attrTempMap.get("f4");
            if (StringUtils.isNotEmpty(dto.getF4())) {
                dto.setF4(builderFParam(f4, dto.getF4(), f4.getString("fieldType")));
            } else {
                dto.setF4("0");
            }
        }
        if (!Objects.isNull(attrTempMap.get("f5"))) {
            JSONObject f5 = attrTempMap.get("f5");
            dto.setF5(builderFParam(f5, dto.getF5(), f5.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f6"))) {
            JSONObject f6 = attrTempMap.get("f6");
            if (StringUtils.isNotEmpty(dto.getF6())) {
                dto.setF6(builderFParam(f6, dto.getF6(), f6.getString("fieldType")));
            } else {
                dto.setF6("0");
            }
        }
        if (!Objects.isNull(attrTempMap.get("f7"))) {
            JSONObject f7 = attrTempMap.get("f7");
            String values = f7.getString("values");
            List<JSONObject> f1Array = JSONObject.parseArray(values, JSONObject.class);
            StringBuilder sb = new StringBuilder("");
            String pfIds = "";
            pfIds = reIds(pfIds, dto.getF7());
            pfIds = reIds(pfIds, dto.getF13());
            List<GameAttribute> gameAttributes = getGameAttributs(pfIds);
            if (CollectionUtils.isNotEmpty(gameAttributes)) {
                if (CollectionUtils.isNotEmpty(gameAttributes)) {
                    for (GameAttribute gameAttribute : gameAttributes) {
                        for (JSONObject jsonObject : f1Array) {
                            if (jsonObject.getString("fieldName").equals(gameAttribute.getFieldName())) {
                                sb.append("," + jsonObject.getString("id"));
                                break;
                            }
                        }
                    }
                }
            }
            if (StringUtils.isNotEmpty(sb)) {
                dto.setF7(sb.substring(1));
            }
        }
        if (!Objects.isNull(attrTempMap.get("f8"))) {
            JSONObject f8 = attrTempMap.get("f8");
            dto.setF8(builderFParam(f8, dto.getF8(), f8.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f9"))) {
            JSONObject f9 = attrTempMap.get("f9");
            String values = f9.getString("values");
            List<JSONObject> f1Array = JSONObject.parseArray(values, JSONObject.class);
            Map<String, JSONObject> otherIds = f1Array.stream().collect(Collectors.toMap(s -> s.getString("fieldName"), s -> s));
            dto.setF9(otherIds.get("是").getString("id"));
        }
        if (!Objects.isNull(attrTempMap.get("f10"))) {
            JSONObject f10 = attrTempMap.get("f10");
            if (StringUtils.isNotEmpty(dto.getF10())) {
                String shiming = "";
                GameAttribute attribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF10()));
                if (!Objects.isNull(attribute)) {
                    if (attribute.getFieldName().equals("可修改实名")) {
                        shiming = "有修改人脸机会/实名是本人";
                    } else {
                        shiming = "无修改人脸机会/实名是本人";
                    }
                }
                String values = f10.getString("values");
                List<JSONObject> f1Array = JSONObject.parseArray(values, JSONObject.class);
                Map<String, JSONObject> otherIds = f1Array.stream().collect(Collectors.toMap(s -> s.getString("fieldName"), s -> s));
                if (!Objects.isNull(otherIds.get(shiming))) {
                    dto.setF10(otherIds.get(shiming).getString("id"));
                } else {
                    System.out.println("未找到精准项 : " + shiming);
                }
            }
        }
        if (!Objects.isNull(attrTempMap.get("f11"))) {
            JSONObject f11 = attrTempMap.get("f11");
            dto.setF11(builderFParam(f11, dto.getF11(), f11.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f11"))) {
            JSONObject f11 = attrTempMap.get("f11");
            dto.setF11(builderFParam(f11, dto.getF15(), f11.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f12"))) {
            JSONObject f12 = attrTempMap.get("f12");
            String values = f12.getString("values");
            List<JSONObject> f1Array = JSONObject.parseArray(values, JSONObject.class);
            StringBuilder sb = new StringBuilder("");
            if (StringUtils.isNotEmpty(dto.getF12())) {
                List<GameAttribute> gameAttributes = gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(dto.getF12().split(","), Long.class));
                if (CollectionUtils.isNotEmpty(gameAttributes)) {
                    for (GameAttribute gameAttribute : gameAttributes) {
                        for (JSONObject jsonObject : f1Array) {
                            if (jsonObject.getString("fieldName").contains(gameAttribute.getFieldName())) {
                                sb.append("," + jsonObject.getString("id"));
                                break;
                            }
                        }
                    }
                }
            }
            if (StringUtils.isNotEmpty(sb)) {
                dto.setF12(sb.substring(1));
            }
        }
        if (!Objects.isNull(attrTempMap.get("f13"))) {
            JSONObject f13 = attrTempMap.get("f13");
            dto.setF13(builderFParam(f13, dto.getF13(), f13.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f14"))) {
            JSONObject f14 = attrTempMap.get("f14");
            dto.setF14(builderFParam(f14, dto.getF14(), f14.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f15"))) {
            JSONObject f15 = attrTempMap.get("f15");
            dto.setF15(builderFParam(f15, dto.getF15(), f15.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f16"))) {
            JSONObject f16 = attrTempMap.get("f16");
            dto.setF16(builderFParam(f16, dto.getF16(), f16.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f17"))) {
            JSONObject f17 = attrTempMap.get("f17");
            dto.setF17(builderFParam(f17, dto.getF17(), f17.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f18"))) {
            JSONObject f18 = attrTempMap.get("f18");
            dto.setF18(builderFParam(f18, dto.getF18(), f18.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f19"))) {
            JSONObject f19 = attrTempMap.get("f19");
            dto.setF19(builderFParam(f19, dto.getF19(), f19.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f20"))) {
            JSONObject f20 = attrTempMap.get("f20");
            dto.setF20(builderFParam(f20, dto.getF20(), f20.getString("fieldType")));
        }
    }

    public void wzry(GoodsInfoAndAttrValueDto dto, Map<String, JSONObject> attrTempMap) {
        if (!Objects.isNull(attrTempMap.get("f1"))) {
            JSONObject f1 = attrTempMap.get("f1");
            dto.setF1(builderFParam(f1, dto.getF1(), f1.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f2"))) {
            JSONObject f2 = attrTempMap.get("f2");
            dto.setF2(builderFParam(f2, dto.getF2(), f2.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f3"))) {
            JSONObject f3 = attrTempMap.get("f3");
            dto.setF3(builderFParam(f3, dto.getF3(), f3.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f4"))) {
            JSONObject f4 = attrTempMap.get("f4");
            dto.setF4(builderFParam(f4, dto.getF4(), f4.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f5"))) {
            JSONObject f5 = attrTempMap.get("f5");
            dto.setF5(builderFParam(f5, dto.getF5(), f5.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f6"))) {
            JSONObject f6 = attrTempMap.get("f6");
            dto.setF6(builderFParam(f6, dto.getF6(), f6.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f7"))) {
            JSONObject f7 = attrTempMap.get("f7");
            dto.setF7(builderFParam(f7, dto.getF7(), f7.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f8"))) {
            JSONObject f8 = attrTempMap.get("f8");
            dto.setF8(builderFParam(f8, dto.getF8(), f8.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f9"))) {
            JSONObject f9 = attrTempMap.get("f9");
            dto.setF9(builderFParam(f9, dto.getF9(), f9.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f10"))) {
            JSONObject f10 = attrTempMap.get("f10");
            dto.setF10(builderFParam(f10, dto.getF10(), f10.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f11"))) {
            JSONObject f11 = attrTempMap.get("f11");
            dto.setF11(builderFParam(f11, dto.getF11(), f11.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f12"))) {
            JSONObject f12 = attrTempMap.get("f12");
            dto.setF12(builderFParam(f12, dto.getF12(), f12.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f13"))) {
            JSONObject f13 = attrTempMap.get("f13");
            dto.setF13(builderFParam(f13, dto.getF13(), f13.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f14"))) {
            JSONObject f14 = attrTempMap.get("f14");
            dto.setF14(builderFParam(f14, dto.getF14(), f14.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f15"))) {
            JSONObject f15 = attrTempMap.get("f15");
            dto.setF15(builderFParam(f15, dto.getF15(), f15.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f16"))) {
            JSONObject f16 = attrTempMap.get("f16");
            dto.setF16(builderFParam(f16, dto.getF16(), f16.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f17"))) {
            JSONObject f17 = attrTempMap.get("f17");
            dto.setF17(builderFParam(f17, dto.getF17(), f17.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f18"))) {
            JSONObject f18 = attrTempMap.get("f18");
            dto.setF18(builderFParam(f18, dto.getF18(), f18.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f19"))) {
            JSONObject f19 = attrTempMap.get("f19");
            dto.setF19(builderFParam(f19, dto.getF19(), f19.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f20"))) {
            JSONObject f20 = attrTempMap.get("f20");
            dto.setF20(builderFParam(f20, dto.getF21(), f20.getString("fieldType")));
        }
    }
    public void yjwj(GoodsInfoAndAttrValueDto dto, Map<String, JSONObject> attrTempMap) {
        if(dto.getGameName().equals("英雄联盟")) {
            if(StringUtils.isNotEmpty(dto.getF1())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF1()));
                if(gameAttribute1.getFieldName().equals("可修改实名")){
                    dto.setF1("39494");
                }else {
                    dto.setF1("39496");
                }
            }else {
                dto.setF1("39496");
            }
        }else {
            if (!Objects.isNull(attrTempMap.get("f1"))) {
                JSONObject f1 = attrTempMap.get("f1");
                dto.setF1(builderFParam(f1, dto.getF1(), f1.getString("fieldType")));
            }
        }
        if (!Objects.isNull(attrTempMap.get("f2"))) {
            JSONObject f2 = attrTempMap.get("f2");
            dto.setF2(builderFParam(f2, dto.getF2(), f2.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f3"))) {
            JSONObject f3 = attrTempMap.get("f3");
            dto.setF3(builderFParam(f3, dto.getF3(), f3.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f4"))) {
            JSONObject f4 = attrTempMap.get("f4");
            dto.setF4(builderFParam(f4, dto.getF4(), f4.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f5"))) {
            JSONObject f5 = attrTempMap.get("f5");
            dto.setF5(builderFParam(f5, dto.getF5(), f5.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f6"))) {
            JSONObject f6 = attrTempMap.get("f6");
            dto.setF6(builderFParam(f6, dto.getF6(), f6.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f7"))) {
            JSONObject f7 = attrTempMap.get("f7");
            dto.setF7(builderFParam(f7, dto.getF7(), f7.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f8"))) {
            JSONObject f8 = attrTempMap.get("f8");
            dto.setF8(builderFParam(f8, dto.getF8(), f8.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f9"))) {
            JSONObject f9 = attrTempMap.get("f9");
            dto.setF9(builderFParam(f9, dto.getF9(), f9.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f10"))) {
            JSONObject f10 = attrTempMap.get("f10");
            dto.setF10(builderFParam(f10, dto.getF10(), f10.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f11"))) {
            JSONObject f11 = attrTempMap.get("f11");
            dto.setF11(builderFParam(f11, dto.getF11(), f11.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f12"))) {
            JSONObject f12 = attrTempMap.get("f12");
            dto.setF12(builderFParam(f12, dto.getF12(), f12.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f13"))) {
            JSONObject f13 = attrTempMap.get("f13");
            dto.setF13(builderFParam(f13, dto.getF13(), f13.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f14"))) {
            JSONObject f14 = attrTempMap.get("f14");
            dto.setF14(builderFParam(f14, dto.getF14(), f14.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f15"))) {
            JSONObject f15 = attrTempMap.get("f15");
            dto.setF15(builderFParam(f15, dto.getF15(), f15.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f16"))) {
            JSONObject f16 = attrTempMap.get("f16");
            dto.setF16(builderFParam(f16, dto.getF16(), f16.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f17"))) {
            JSONObject f17 = attrTempMap.get("f17");
            dto.setF17(builderFParam(f17, dto.getF17(), f17.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f18"))) {
            JSONObject f18 = attrTempMap.get("f18");
            dto.setF18(builderFParam(f18, dto.getF18(), f18.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f19"))) {
            JSONObject f19 = attrTempMap.get("f19");
            dto.setF19(builderFParam(f19, dto.getF19(), f19.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f20"))) {
            JSONObject f20 = attrTempMap.get("f20");
            dto.setF20(builderFParam(f20, dto.getF20(), f20.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f21"))) {
            JSONObject f21 = attrTempMap.get("f21");
            dto.setF21(builderFParam(f21, dto.getF21(), f21.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f22"))) {
            JSONObject f22 = attrTempMap.get("f22");
            dto.setF22(builderFParam(f22, dto.getF22(), f22.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f23"))) {
            JSONObject f23 = attrTempMap.get("f23");
            dto.setF23(builderFParam(f23, dto.getF23(), f23.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f24"))) {
            JSONObject f24 = attrTempMap.get("f24");
            dto.setF24(builderFParam(f24, dto.getF24(), f24.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f25"))) {
            JSONObject f25 = attrTempMap.get("f25");
            dto.setF25(builderFParam(f25, dto.getF25(), f25.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f26"))) {
            JSONObject f26 = attrTempMap.get("f26");
            dto.setF26(builderFParam(f26, dto.getF26(), f26.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f27"))) {
            JSONObject f27 = attrTempMap.get("f27");
            dto.setF27(builderFParam(f27, dto.getF27(), f27.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f28"))) {
            JSONObject f28 = attrTempMap.get("f28");
            dto.setF28(builderFParam(f28, dto.getF28(), f28.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f29"))) {
            JSONObject f29 = attrTempMap.get("f29");
            dto.setF29(builderFParam(f29, dto.getF29(), f29.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f30"))) {
            JSONObject f30 = attrTempMap.get("f30");
            dto.setF30(builderFParam(f30, dto.getF30(), f30.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f31"))) {
            JSONObject f31 = attrTempMap.get("f31");
            dto.setF31(builderFParam(f31, dto.getF31(), f31.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f32"))) {
            JSONObject f32 = attrTempMap.get("f32");
            dto.setF32(builderFParam(f32, dto.getF32(), f32.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f33"))) {
            JSONObject f33 = attrTempMap.get("f33");
            dto.setF33(builderFParam(f33, dto.getF33(), f33.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f34"))) {
            JSONObject f34 = attrTempMap.get("f34");
            dto.setF34(builderFParam(f34, dto.getF34(), f34.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f35"))) {
            JSONObject f35 = attrTempMap.get("f35");
            dto.setF35(builderFParam(f35, dto.getF35(), f35.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f36"))) {
            JSONObject f36 = attrTempMap.get("f36");
            dto.setF36(builderFParam(f36, dto.getF36(), f36.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f37"))) {
            JSONObject f37 = attrTempMap.get("f37");
            dto.setF37(builderFParam(f37, dto.getF37(), f37.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f38"))) {
            JSONObject f38 = attrTempMap.get("f38");
            dto.setF38(builderFParam(f38, dto.getF38(), f38.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f39"))) {
            JSONObject f39 = attrTempMap.get("f39");
            dto.setF39(builderFParam(f39, dto.getF39(), f39.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f40"))) {
            JSONObject f40 = attrTempMap.get("f40");
            dto.setF40(builderFParam(f40, dto.getF40(), f40.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f41"))) {
            JSONObject f41 = attrTempMap.get("f41");
            dto.setF41(builderFParam(f41, dto.getF46(), f41.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f42"))) {
            JSONObject f42 = attrTempMap.get("f42");
            dto.setF42(builderFParam(f42, dto.getF47(), f42.getString("fieldType")));
        }
    }

    public void ys(GoodsInfoAndAttrValueDto dto, Map<String, JSONObject> attrTempMap) {
        if (!Objects.isNull(attrTempMap.get("f1"))) {
            JSONObject f1 = attrTempMap.get("f1");
            dto.setF1(builderFParam(f1, dto.getF1(), f1.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f2"))) {
            JSONObject f2 = attrTempMap.get("f2");
            dto.setF2(builderFParam(f2, dto.getF2(), f2.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f3"))) {
            JSONObject f3 = attrTempMap.get("f3");
            dto.setF3(builderFParam(f3, dto.getF3(), f3.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f4"))) {
            JSONObject f4 = attrTempMap.get("f4");
            dto.setF4(builderFParam(f4, dto.getF4(), f4.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f5"))) {
            JSONObject f5 = attrTempMap.get("f5");
            dto.setF5(builderFParam(f5, dto.getF5(), f5.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f6"))) {
            JSONObject f6 = attrTempMap.get("f6");
            dto.setF6(builderFParam(f6, dto.getF6(), f6.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f7"))) {
            JSONObject f7 = attrTempMap.get("f7");
            dto.setF7(builderFParam(f7, dto.getF7(), f7.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f8"))) {
            JSONObject f8 = attrTempMap.get("f8");
            dto.setF8(builderFParam(f8, dto.getF8(), f8.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f9"))) {
            JSONObject f9 = attrTempMap.get("f9");
            dto.setF9(builderFParam(f9, dto.getF9(), f9.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f11"))) {
            JSONObject f11 = attrTempMap.get("f11");
            dto.setF11(builderFParam(f11, dto.getF11(), f11.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f17"))) {
            JSONObject f17 = attrTempMap.get("f17");
            dto.setF17(builderFParam(f17, dto.getF17(), f17.getString("fieldType")));
        }
        dto.setF20("41653");
    }

    public void lol(GoodsInfoAndAttrValueDto dto, String attrTempMap) {
//        String data = JSONObject.parseObject(attrTempMap).getString("data");
        JSONArray jsonArray = JSONArray.parseArray(attrTempMap);
        for (Object o : jsonArray) {
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("实名")) {
                if (StringUtils.isNotEmpty(dto.getF1())) {
                    GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF1()));
                    if (gameAttribute1.getFieldName().equals("可修改实名")) {
                        dto.setF1("39494");
                    } else {
                        dto.setF1("39496");
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("单双段位")) {
                dto.setF2("39501");
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("峡谷之巅资格")) {
                dto.setF6("39511");
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("限定")) {
                if (StringUtils.isNotEmpty(dto.getF19())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF19());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName())) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF7(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("至臻")) {
                if (StringUtils.isNotEmpty(dto.getF8())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF8());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName().replace("至臻", ""))) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF8(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("海克斯")) {
                if (StringUtils.isNotEmpty(dto.getF9())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF9());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName().replace("海克斯", "")
                                    .replace("小炮", "崔丝塔娜").replace("皇子", "嘉文四世").replace("鳄鱼", "雷克顿").replace("摄魂", "")
                                    .replace("乌鸦", "斯维因").replace("恐惧新星诺手", "海克斯恐惧新星德莱厄斯").replace("老牛", "阿利斯塔")
                                    .replace("大嘴", "克格莫"))) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF9(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("年限")) {
                if (StringUtils.isNotEmpty(dto.getF10())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF10());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName().replace("武器", "贾克斯"))) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF10(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("周年")) {
                if (StringUtils.isNotEmpty(dto.getF11())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF11());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName().replace("一周年安妮", "1周年安妮梦游仙境")
                                    .replace("两周年诺手", "2周年勇敢的心德莱厄斯").replace("三周年女枪", "3周年女枪")
                                    .replace("四周年锐雯", "4周年锐雯").replace("五周年阿狸", "五周年阿狸")
                                    .replace("六周年EZ", "6周年伊泽瑞尔").replace("七周年刀妹", "7周年艾瑞莉娅")
                                    .replace("八周年佐伊", "8周年佐伊").replace("九周年剑圣", "9周年剑圣")
                                    .replace("十周年萨勒芬妮", "10周年萨勒芬妮").replace("十周年霞", "10周年霞")
                                    .replace("十一周年卡密尔", "11周年卡蜜尔").replace("十一周年卢锡安", "11周年卢锡安"))) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF11(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("情人节限定")) {
                if (StringUtils.isNotEmpty(dto.getF12())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF12());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName().replace("娑娜", "琴女"))) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF12(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("冰雪节限定")) {
                if (StringUtils.isNotEmpty(dto.getF13())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF13());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName().replace("冬境仙灵索拉卡", "冬季仙境奶妈")
                                    .replace("北极星神佐伊", "北极星守望者佐伊").replace("圣诞糖果棒厄运小姐", "圣诞糖果棒女枪").replace("平安夜女神娑娜", "平安夜女神琴女")
                                    .replace("持胡萝卜的雪人易", "持胡萝卜的雪人剑圣").replace("狂心冰王图奇", "狂心冰王老鼠").replace("北极星小丑", "北极星使者小丑")
                                    .replace("北极星时光", "北极星圣贤基兰").replace("北极星狼人", "北极星使者沃里克").replace("北极星乌鸦", "北极星猎人斯维因"))) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF13(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("冠军限定系列")) {
                if (StringUtils.isNotEmpty(dto.getF15())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF15());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName().replace("男枪", "格雷福斯")
                                    .replace("悠米", "猫咪").replace("盲僧", "李青")
                                    .replace("石头人", "墨菲特").replace("船长", "普朗克")
                                    .replace("刀妹", "艾瑞莉娅").replace("剑姬", "菲奥娜")
                                    .replace("亚托克斯", "剑魔"))) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF15(string.substring(1));
                    }
                }
            }
            if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("终极皮肤")) {
                if (StringUtils.isNotEmpty(dto.getF17())) {
                    String values = JSONObject.parseObject(o.toString()).getString("values");
                    JSONArray jsonArray1 = JSONArray.parseArray(values);
                    List<GameAttribute> list = getGameAttributs(dto.getF17());
                    String string = "";
                    for (GameAttribute gameAttribute1 : list) {
                        for (Object p : jsonArray1) {
                            if (JSONObject.parseObject(p.toString()).getString("fieldName").contains(gameAttribute1.getFieldName())) {
                                string += "," + JSONObject.parseObject(p.toString()).getString("id");
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(string)) {
                        dto.setF17(string.substring(1));
                    }
                }
            }

        }
    }

    private List<GameAttribute> getGameAttributs(String ids) {
        return gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                Long.class));
    }

    public void sgs(GoodsInfoAndAttrValueDto dto, Map<String, JSONObject> attrTempMap) {
        if (!Objects.isNull(attrTempMap.get("f1"))) {
            JSONObject f1 = attrTempMap.get("f1");
            dto.setF1(builderFParam(f1, dto.getF1(), f1.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f2"))) {
            JSONObject f2 = attrTempMap.get("f2");
            dto.setF2(builderFParam(f2, dto.getF2(), f2.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f3"))) {
            JSONObject f3 = attrTempMap.get("f3");
            dto.setF3(builderFParam(f3, dto.getF3(), f3.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f4"))) {
            JSONObject f4 = attrTempMap.get("f4");
            dto.setF4(builderFParam(f4, dto.getF4(), f4.getString("fieldType")));
        }
    }

    public void hyrz(GoodsInfoAndAttrValueDto dto, Map<String, JSONObject> attrTempMap) {
        if (!Objects.isNull(attrTempMap.get("f1"))) {
            JSONObject f1 = attrTempMap.get("f1");
            dto.setF1(builderFParam(f1, dto.getF1(), f1.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f2"))) {
            JSONObject f2 = attrTempMap.get("f2");
            dto.setF2(builderFParam(f2, dto.getF2(), f2.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f3"))) {
            JSONObject f3 = attrTempMap.get("f3");
            dto.setF3(builderFParam(f3, dto.getF3(), f3.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f7"))) {
            JSONObject f7 = attrTempMap.get("f7");
            dto.setF7(builderFParam(f7, dto.getF7(), f7.getString("fieldType")));
        }
    }

    public void defaultInfo(GoodsInfoAndAttrValueDto dto, Map<String, JSONObject> attrTempMap) {
        if(dto.getGameName().equals("英雄联盟")) {
            if(StringUtils.isNotEmpty(dto.getF1())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(dto.getF1()));
                if(gameAttribute1.getFieldName().equals("可修改实名")){
                    dto.setF1("39494");
                }else {
                    dto.setF1("39496");
                }
            }else {
                dto.setF1("39496");
            }
        }else {
            if (!Objects.isNull(attrTempMap.get("f1"))) {
                JSONObject f1 = attrTempMap.get("f1");
                dto.setF1(builderFParam(f1, dto.getF1(), f1.getString("fieldType")));
            }
        }
        if (!Objects.isNull(attrTempMap.get("f2"))) {
            JSONObject f2 = attrTempMap.get("f2");
            dto.setF2(builderFParam(f2, dto.getF2(), f2.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f3"))) {
            JSONObject f3 = attrTempMap.get("f3");
            dto.setF3(builderFParam(f3, dto.getF3(), f3.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f4"))) {
            JSONObject f4 = attrTempMap.get("f4");
            dto.setF4(builderFParam(f4, dto.getF4(), f4.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f5"))) {
            JSONObject f5 = attrTempMap.get("f5");
            dto.setF5(builderFParam(f5, dto.getF5(), f5.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f6"))) {
            JSONObject f6 = attrTempMap.get("f6");
            dto.setF6(builderFParam(f6, dto.getF6(), f6.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f7"))) {
            JSONObject f7 = attrTempMap.get("f7");
            dto.setF7(builderFParam(f7, dto.getF7(), f7.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f8"))) {
            JSONObject f8 = attrTempMap.get("f8");
            dto.setF8(builderFParam(f8, dto.getF8(), f8.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f9"))) {
            JSONObject f9 = attrTempMap.get("f9");
            dto.setF9(builderFParam(f9, dto.getF9(), f9.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f10"))) {
            JSONObject f10 = attrTempMap.get("f10");
            dto.setF10(builderFParam(f10, dto.getF10(), f10.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f11"))) {
            JSONObject f11 = attrTempMap.get("f11");
            dto.setF11(builderFParam(f11, dto.getF11(), f11.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f12"))) {
            JSONObject f12 = attrTempMap.get("f12");
            dto.setF12(builderFParam(f12, dto.getF12(), f12.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f13"))) {
            JSONObject f13 = attrTempMap.get("f13");
            dto.setF13(builderFParam(f13, dto.getF13(), f13.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f14"))) {
            JSONObject f14 = attrTempMap.get("f14");
            dto.setF14(builderFParam(f14, dto.getF14(), f14.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f15"))) {
            JSONObject f15 = attrTempMap.get("f15");
            dto.setF15(builderFParam(f15, dto.getF15(), f15.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f16"))) {
            JSONObject f16 = attrTempMap.get("f16");
            dto.setF16(builderFParam(f16, dto.getF16(), f16.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f17"))) {
            JSONObject f17 = attrTempMap.get("f17");
            dto.setF17(builderFParam(f17, dto.getF17(), f17.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f18"))) {
            JSONObject f18 = attrTempMap.get("f18");
            dto.setF18(builderFParam(f18, dto.getF18(), f18.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f19"))) {
            JSONObject f19 = attrTempMap.get("f19");
            dto.setF19(builderFParam(f19, dto.getF19(), f19.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f20"))) {
            JSONObject f20 = attrTempMap.get("f20");
            dto.setF20(builderFParam(f20, dto.getF20(), f20.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f21"))) {
            JSONObject f21 = attrTempMap.get("f21");
            dto.setF21(builderFParam(f21, dto.getF21(), f21.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f22"))) {
            JSONObject f22 = attrTempMap.get("f22");
            dto.setF22(builderFParam(f22, dto.getF22(), f22.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f23"))) {
            JSONObject f23 = attrTempMap.get("f23");
            dto.setF23(builderFParam(f23, dto.getF23(), f23.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f24"))) {
            JSONObject f24 = attrTempMap.get("f24");
            dto.setF24(builderFParam(f24, dto.getF24(), f24.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f25"))) {
            JSONObject f25 = attrTempMap.get("f25");
            dto.setF25(builderFParam(f25, dto.getF25(), f25.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f26"))) {
            JSONObject f26 = attrTempMap.get("f26");
            dto.setF26(builderFParam(f26, dto.getF26(), f26.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f27"))) {
            JSONObject f27 = attrTempMap.get("f27");
            dto.setF27(builderFParam(f27, dto.getF27(), f27.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f28"))) {
            JSONObject f28 = attrTempMap.get("f28");
            dto.setF28(builderFParam(f28, dto.getF28(), f28.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f29"))) {
            JSONObject f29 = attrTempMap.get("f29");
            dto.setF29(builderFParam(f29, dto.getF29(), f29.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f30"))) {
            JSONObject f30 = attrTempMap.get("f30");
            dto.setF30(builderFParam(f30, dto.getF30(), f30.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f31"))) {
            JSONObject f31 = attrTempMap.get("f31");
            dto.setF31(builderFParam(f31, dto.getF31(), f31.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f32"))) {
            JSONObject f32 = attrTempMap.get("f32");
            dto.setF32(builderFParam(f32, dto.getF32(), f32.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f33"))) {
            JSONObject f33 = attrTempMap.get("f33");
            dto.setF33(builderFParam(f33, dto.getF33(), f33.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f34"))) {
            JSONObject f34 = attrTempMap.get("f34");
            dto.setF34(builderFParam(f34, dto.getF34(), f34.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f35"))) {
            JSONObject f35 = attrTempMap.get("f35");
            dto.setF35(builderFParam(f35, dto.getF35(), f35.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f36"))) {
            JSONObject f36 = attrTempMap.get("f36");
            dto.setF36(builderFParam(f36, dto.getF36(), f36.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f37"))) {
            JSONObject f37 = attrTempMap.get("f37");
            dto.setF37(builderFParam(f37, dto.getF37(), f37.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f38"))) {
            JSONObject f38 = attrTempMap.get("f38");
            dto.setF38(builderFParam(f38, dto.getF38(), f38.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f39"))) {
            JSONObject f39 = attrTempMap.get("f39");
            dto.setF39(builderFParam(f39, dto.getF39(), f39.getString("fieldType")));
        }
        if (!Objects.isNull(attrTempMap.get("f40"))) {
            JSONObject f40 = attrTempMap.get("f40");
            dto.setF40(builderFParam(f40, dto.getF40(), f40.getString("fieldType")));
        }
    }
    private String guolvJYM(String des) {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType("jym_check");
        sysDictData.setStatus(Constants.STR_0);
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataList(sysDictData);
        for (SysDictData dictData : sysDictDataList) {
            String value = dictData.getDictValue();
            if (des.contains(value)) {
                des = des.replace(value, "");
            }
        }
        return des;
    }


    public static String getCover(Map<String, Object> params) {
        StringBuffer resut = new StringBuffer();
        for (String key : params.keySet()) {
            Object value = params.get(key);
            if (key.equals("urlArr")) {
                Object a = params.get(key);
                value = a.toString().replace("}, ", "},");
            }
            resut.append(key + "=" + value + "&");
        }
        return resut.toString();
    }

    public static void main(String[] args) {
        SalePartner salePartner = new SalePartner();
        salePartner.setSaleKey("hs230952850019043");
        salePartner.setOther("rlsya0r727vx566np2kkqiegow3lp5e9vvvzetsekcn");
        salePartner.setTwoOther("https://api.kkzhw.com");
        String s = upLoad("https://imgv2.zuyoul.com/2c97e7c98b6654cb018b6f969d6c064f.jpg", salePartner);
        System.out.println(s);
    }

    public static String getCover1(Map<String, String> params) {
        StringBuffer resut = new StringBuffer();
        for (String key : params.keySet()) {
            resut.append(key + "=" + params.get(key) + "&");
        }
        return resut.toString();
    }

    //获取token
    public String getToken() {

        String token = "";
        try {
            token = redisCache.getCacheObject(descTitle + "_token_yudu2.0.1");
            if (StringUtils.isNotEmpty(token)) {
                return token;
            }
        } catch (Exception e) {

        }

        Map<String, String> params = new TreeMap<>();
        long timestamp = System.currentTimeMillis();
        String cover = timestamp + APPID + APPSECRET;
        String sign = DigestUtils.md5Hex(cover);
        params.put("timestamp", String.valueOf(timestamp));
        params.put("sign", sign);
        Map<String, String> action1 = new TreeMap<>();
        action1.put("appId", APPID);
        String response = null;
        try {
            response = interfaceFeignService.api_token(String.valueOf(timestamp), sign, APPID);
        } catch (Exception e) {
            throw new GlobalException("获取token 失败! errMsg :" + e.getMessage());
        }
        String data = JSONObject.parseObject(response).getString("data");
        token = JSONObject.parseObject(data).getString("token");
        try {
            redisCache.setCacheObject(descTitle + "_token_yudu2.0.1", token, 3, TimeUnit.MINUTES);
        } catch (Exception e) {

        }
        return token;

    }

    public String getGameInfoV2(Long gameId) {
        try {
            Map<String, String> params = new TreeMap<>();
            long timestamp = System.currentTimeMillis();
            String cover = timestamp + APPID + APPSECRET;
            String sign = DigestUtils.md5Hex(cover);
            params.put("timestamp", String.valueOf(timestamp));
            params.put("sign", sign);
            Map<String, String> action1 = new TreeMap<>();
            action1.put("appId", APPID);
            String response = interfaceFeignService.api_token(String.valueOf(timestamp), sign, APPID);
            String data = JSONObject.parseObject(response).getString("data");
            String token = JSONObject.parseObject(data).getString("token");

            AjaxResult info = interfaceFeignService.getGameInfo(token, String.valueOf(timestamp), sign, gameId);
            return JSONObject.toJSONString(info.get("data"));
        } catch (Exception e) {
            throw new GlobalException("获取GameInfo : " + gameId + "失败! errMsg :" + e.getMessage());
        }
    }

    public String getGameAttrTempV2(String gameName) {
        return GameContentUtils.getGameAttrTemp(gameName);
    }

    public String getGameAttrTempV2(Long gameId) {
        try {
            AjaxResult info = null;
            try {
                ApiResponse apiResponse = redisCache.getCacheObject("GameAttrTemp" + gameId);
                if (Objects.nonNull(apiResponse)) {
                    return JSONObject.toJSONString(apiResponse.getData());
                }
            }catch (Exception exception){

            }
            Map<String, String> params = new TreeMap<>();
            long timestamp = System.currentTimeMillis();
            String cover = timestamp + APPID + APPSECRET;
            String sign = DigestUtils.md5Hex(cover);
            params.put("timestamp", String.valueOf(timestamp));
            params.put("sign", sign);
            Map<String, String> action1 = new TreeMap<>();
            action1.put("appId", APPID);
            String response = interfaceFeignService.api_token(String.valueOf(timestamp), sign, APPID);
            String data = JSONObject.parseObject(response).getString("data");
            String token = JSONObject.parseObject(data).getString("token");
            info = interfaceFeignService.getGameAttrTemp(token, String.valueOf(timestamp), sign, gameId);
            try {
                redisCache.setCacheObject("GameAttrTemp" + gameId, ApiResponse.success(info.get("data")), 5, TimeUnit.MINUTES);
            }catch (Exception e){

            }
            return JSONObject.toJSONString(info.get("data"));
        } catch (Exception e) {
            throw new GlobalException("GameAttrTemp : " + gameId + "失败! errMsg :" + e.getMessage());
        }
    }

    private void initialization() {
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("interface_adapter_config");
        if (CollectionUtils.isNotEmpty(sysDictDataList)) {
            for (SysDictData sysDictData : sysDictDataList) {
                if (StringUtils.equals("APPID", sysDictData.getDictLabel())) {
                    this.APPID = sysDictData.getDictValue();
                }
                if (StringUtils.equals("APPSECRET", sysDictData.getDictLabel())) {
                    this.APPSECRET = sysDictData.getDictValue();
                }
                if (StringUtils.equals("APPFLAGTITLE", sysDictData.getDictLabel())) {
                    this.APPFLAGTITLE = sysDictData.getDictValue();
                }
                if (StringUtils.equals("APPFLAGDES", sysDictData.getDictLabel())) {
                    this.APPFLAGDES = sysDictData.getDictValue();
                }
            }
        } else {
            throw new GlobalException("接口服务信息未配置");
        }
    }

    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

    public static String createQQAccount() {
        int num = 8;
        String[] vec = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
        num = num <= 0 ? 1 : num;
        StringBuffer str = new StringBuffer(10);
        for (int i = 0; i < num; i++) {
            int r1 = Long.valueOf(Math.round(Math.random() * (vec.length - 1))).intValue();
            str.append(vec[r1]);
        }
        return str.toString();
    }

    //创游图片上传
    public static String uploadImgChuangYou(String img) {
        Map<String, String> params = new HashMap<>();
        params.put("path", img);
        System.out.println("开始：" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        String result = HttpUtils.doPostForm("https://cy227.com/api/web/v1/common/fetchFile", params, null);
        System.out.println("结束：" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getNowDate()));
        String data = JSONObject.parseObject(result).getString("data");
        String url = JSONObject.parseObject(data).getString("url");
        return url;
    }
}
